package test01.validator;

import test01.utils.ValidatorUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IsAgeValidator implements ConstraintValidator<IsAge, Integer> {
    private boolean required = false;
    @Override
    public void initialize(IsAge constraintAnnotation) {
        required = constraintAnnotation.required();
    }

    @Override
    public boolean isValid(Integer age, ConstraintValidatorContext constraintValidatorContext) {
        if(required) {
            return ValidatorUtil.isAge(age);
        }
        return false;
    }
}
